home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: c
- Date: Thu, 25 Jan 1996 13:50:12 +0200
- Organization: Carelcomp Forest
- Message-ID: <31076E74.128A@cmt.lpr.mail.carel.fi>
- References: <4e7lmg$ghh@chaos.kulnet.kuleuven.ac.be>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Andreas De Troy wrote:
- > [original question snipped]
- >
- > The problem could be that your editor adds an "end-of-file"-marker at the
- > end of its file (ASCII-code 26 or 27 [Ctrl-Z], I don't know). The
- > fprintf()-function adds its characters AFTER this eof-marker.
- >
- > When you load the file in your editor, it stops reading input when it
- > encounters this eof-marker, so it will not let you see what comes after
- > it. A binary dump should reveal, however, that the appended words are
- > really there.
- >
- > Solutions:
- > 1. try another editor; some do *not* append this eof-mark
- > 2. keep your ASCII-file clean", i.e. do not save it with your editor. The
- > Borland-functions will not append eof-marks, so as long as your file is
- > exclusively produced by these functions, everything should work fine.
-
- Or, 3. Try:
-
- FILE *fp = fopen(filename, "r");
- FILE *out = fopen("temp.txt", "w");
- char buf[long_enough];
-
- while (fgets(buf, sizeof(buf), fp))
- fprintf(out, "%s", buf);
- fprintf(out, "New line of text\n");
- fclose(fp);
- fclose(out);
- remove(filename);
- rename("temp.txt", filename);
-
- Later,
- AriL
-
- --
- All my opinions are mine and mine alone.
-